<%@page import="es.usj.tac.meteorologica.dto.City"%>
<%@page import="java.util.List"%>
<%@page import="es.usj.tac.meteorologica.dto.Weather"%>
<%-- <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> --%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"  %>
<% String type="";
if(request.getParameter("type") != null){
	type = (String)request.getParameter("type");
}else if(request.getAttribute("type") != null){
	type = (String)request.getAttribute("type");
}
%>
	<%if("weather".equals(type)){ %>
			
<%@page import="es.usj.tac.meteorologica.dao.DAOFactory"%>
<%@page import="es.usj.tac.meteorologica.dto.Country"%><form id="weatherForm" action="getWeather.htm" method="POST">
				<fieldset>
					<legend>Seleccione el tiempo de una ciudad</legend>
					<div class="lineForm">
						<label for="countryName">Pa&iacute;s</label>
						<input type="text" name="countryName" required="required" id="countryName" tabindex="1" value=""/>
					</div>
					<div class="lineForm">
						<label for="cityName">Ciudad</label>
						<input type="text" name="cityName" required="required" id="cityName" tabindex="2" value=""/>
					</div>
					<div class="lineForm">
						<input type="submit" value="Consultar" name="submitBtn" tabindex="3"/>
					</div>
				</fieldset>
			</form>
		
			<div id="resultForm">
				<%if(request.getAttribute("weather") != null){ 
				Weather weather = (Weather) request.getAttribute("weather");%>
				<table summary="Resultado de la llamada al WS Weather" class="results">
					<tbody>
						<tr>
							<td class="titleCell">Localizaci&oacute;n</td>
							<td><c:out  value="${weather.location}"/></td>
						</tr>
						<tr>
							<td class="titleCell">Hora</td>
							<td><c:out value="${weather.time}"/></td>
						</tr>
						<tr>
							<td class="titleCell">Visibilidad</td>
							<td><c:out value="${weather.visibility}"/></td>
						</tr>
						<tr>
							<td class="titleCell">Viento</td>
							<td><c:out value="${weather.wind}"/></td>
						</tr>
						<tr>
							<td class="titleCell">Temperatura (F)</td>
							<td><c:out value="${weather.temperatureInF}"/></td>
						</tr>
						<tr>
							<td class="titleCell">Temperatura (C)</td>
							<td><c:out value="${weather.temperatureInC}"/></td>
						</tr>
						<tr>
							<td class="titleCell">Dew Point (F)</td>
							<td><c:out value="${weather.dewPointInF}"/></td>
						</tr>
						<tr>
							<td class="titleCell">Dew Point (C)</td>
							<td><c:out value="${weather.dewPointInC}"/></td>
						</tr>
						<tr>
							<td class="titleCell">Humedad Relativa</td>
							<td><c:out value="${weather.relativeHumidity}"/></td>
						</tr>
						<tr>
							<td class="titleCell">Presi&oacute;n</td>
							<td><c:out value="${weather.pressure}"/></td>
						</tr>
						<tr>
							<td class="titleCell">Estado</td>
							<td>
								<c:choose>
									<c:when test="${weather.status==true}"><img src="jsp/images/tick.png" alt="OK"/></c:when>
									<c:otherwise><img src="jsp/images/delete.png" alt="KO"/></c:otherwise>
								</c:choose>
							</td>
						</tr>
					</tbody>
				</table>
				<%} %>
			</div>
		<%}else if("city".equals(type)){ %>
			<form action="getCities.htm" method="POST">
				<fieldset>
					<legend>Seleccione las ciudades de un pa&iacute;s</legend>
					<div class="lineForm">
						<label for="country">Pa&iacute;s</label>
						<input type="text" name="countryName" required="required" id="country" tabindex="1" value=""/>
					</div>
					<div class="lineForm">
						<input type="submit" value="Consultar" tabindex="2" name="submitBtn"/>
					</div>
				</fieldset>
			</form>	
			<div id="resultForm">
			
				<%if(request.getAttribute("cities") != null){
					List<City> citiesArray = (List<City>)request.getAttribute("cities");
					if(citiesArray.size() == 0){%>
						<table summary="Resultado de la llamada al WS Weather" class="results">
							<tr>
	               				<td class="titleCell"><c:out value="SIN RESULTADOS"/></td>
	               			</tr>
						</table>
				<%
					}else{%>
						<table summary="Resultado de la llamada al WS Weather" class="results">
							<c:forEach items="${cities}" var="city" varStatus="status">
		               			<tr>
		               				<td class="titleCell">Nombre</td>
		               				<td><c:out value="${city.name}"/></td>
		               			</tr>
		               		</c:forEach>
						</table>
				<%}
				}%>
			</div>	
		<%} %>
